<?php
class My_PhotoWallController extends MM_Controller_My_Action
{	
	/**
	 * @var MM_Service_Admin_Event
	 */
	private $serviceE = null;
		
	/**
	 * 初始化
	 */
	public function init()
	{
		parent::init();
		$this->serviceE = new MM_Service_Admin_Event();
	}
	
	/**
	 * index
	 */
	public function indexAction()
	{
		//TODO: 做ajax的定时获取操作
		$fid = 0;
		$event = null;
		$file 	= new MM_Service_Admin_EventFiles();
		$eid = $_POST['eid'];
		$where 	= sprintf("eid = '%s' AND status = 1",$eid);
		$order 	= "addtime desc";
		$r = $file->fetchAll(null,null,$where,$order,true);
		$data['total'] = 0;
		if($r->getCode()){
			$photo = $r->getData();
			$data['total'] = count($photo);
			//获取第1条记录的fid用作回调时使用
			if($data['total']>0){
				$fid = $photo[0]['fid'];
			}
			$data['fid'] = $fid;
			$data['photo'] = $photo;
		}
		
		$service = new MM_Service_Admin_Event();
		$r1 = $service->find($eid,true);
		$event = $r1->getData();
		$this->pageview->assign("photo",$data);
		$this->pageview->assign("event",$event);
		$this->helper->setPageView($this->pageview, WEB_TITLE, "photowall", null);
	}
	
	public function gAction()
	{
		if ( ($this->uid<1) || ($this->eid<1) ) {
			$this->result = $this->returnResult(Mediad2_Model_Result::CODE_FAILURE,'Miss parameter: uid/eid');
		} else {
			$fid 	= @$this->httpdata['fid'];//作为前台定期传过来的值
			$file 	= new MM_Service_Admin_EventFiles();
			$where 	= sprintf("eid = '%s' AND status = 1",$this->eid);
			$order 	= "addtime desc";
			$msg 	= "normal fn";

			if(is_numeric($fid)){
				$where 	= sprintf("eid = '%s' AND status = 1 AND fid > '%s'",$this->eid,$fid);
				$msg 	= "ext fn";
			}
			
			$r = $file->fetchAll(null,null,$where,$order,true);
			if($r->getCode()){	
				$photo = $r->getData();			
				$data['total'] = count($photo);
				//获取第1条记录的fid用作回调时使用
				if($data['total']>0){
					$fid = $photo[0]['fid'];
				}
				$data['fid'] = $fid;
				$data['photo'] = $photo;
				$this->result  = $this->returnResult(1,$msg,$data);
			}else{
				$this->result  = $this->returnResult(0,"system error!");
			}
			
		}
		echo $this->encodeResult($this->result);
	}
	
}